import { createSlice, PayloadAction } from '@reduxjs/toolkit'

export type UserSliceType = {
  username: string
  nickname: string
}

const INIT_STATE: UserSliceType = {
  username: '',
  nickname: '',
}

export const userSlice = createSlice({
  name: 'user',
  initialState: INIT_STATE,
  reducers: {
    loginReducer: (state: UserSliceType, action: PayloadAction<UserSliceType>) => action.payload, //设置 username,nickname
    logoutReducer: () => INIT_STATE,
  },
})

export const { loginReducer, logoutReducer } = userSlice.actions

export default userSlice.reducer
